package com.hfkh.keyun.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkh.keyun.entity.VisitHistory;
import com.hfkh.keyun.mapper.VisitHistoryMapper;
import com.hfkh.keyun.service.VisitHistoryService;

import com.hfkh.keyun.util.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class VisitHistoryServiceImpl extends ServiceImpl<VisitHistoryMapper,VisitHistory> implements VisitHistoryService {

    @Resource
    private VisitHistoryMapper visitHistoryMapper;


    @Override
    public List<VisitHistory> selVisitHistory(Integer userId) {
        return visitHistoryMapper.selVisitHistory(userId);
    }

    @Override
    public PageResult<List<VisitHistory>> selVisitHistoryPage(Integer userId, Integer page, Integer size) {
        PageResult<List<VisitHistory>> pageResult = new PageResult<>();
        // 启动分页
        PageHelper.startPage(page, size, true);
        // 获取电子文档列表
        List<VisitHistory> visitHistoryList = visitHistoryMapper.selVisitHistory(userId);
        // PageInfo分页对象
        PageInfo<VisitHistory> pageInfo = new PageInfo<>(visitHistoryList);
        pageResult.setPages(pageInfo.getPages());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setList(pageInfo.getList());
        return pageResult;
    }

    @Override
    public VisitHistory selVisitHistoryById(Integer id) {
        return visitHistoryMapper.selVisitHistoryById(id);
    }
}
